/* GUI CONVERTED from rcsqscmt.p (converter v1.76) Fri May  3 13:22:38 2002 */
/* rcsqscmt.p - CUSTOMER SEQUENCE SCHEDULE MAINTENANCE                    */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                    */
/* All rights reserved worldwide.  This is an unpublished work.           */
/* $Revision: 1.18 $                                                       */
/*V8:ConvertMode=Maintenance                                              */
/* REVISION: 9.1            CREATED: 02/04/99 BY: *N003* Dan Herman       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00 BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00 BY: *N0KP* myb              */
/* $Revision: 1.18 $    BY: Katie Hilbert         DATE: 04/15/02  ECO: *P03J*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

{mfdtitle.i "2+ "}
define new shared variable ship-param1 as character no-undo.
define new shared variable ship-param2 as character no-undo.

define variable del-yn                 like mfc_logical no-undo.
define variable copy-yn                like mfc_logical no-undo.
define variable l_make_active-yn       like mfc_logical no-undo.
define variable l_part                 like pt_part no-undo.
define variable l_cust_part            like cp_cust_part no-undo.
define variable l_shipfrom             like rcs_shipfrom no-undo.
define variable l_shipto               like rcs_shipto no-undo.
define variable l_rlse_id              like rcs_rlse_id no-undo.
define variable mc-error-number        as integer no-undo.
define variable l_update_cum_qty       like mfc_logical no-undo.
define variable l_update_discr_qty     like mfc_logical no-undo.
define variable l_tmp_po               like rcsd_cust_po no-undo.
define variable l_err_stat             like mfc_logical no-undo.
define variable l_shipname             like ad_name no-undo.
define variable l_sitename             like si_desc no-undo.
define variable l_old_qty              like rcsd_cum_qty no-undo.
define variable l_prev_cum_qty         like rcsd_cum_qty no-undo.
define variable l_site_db              like si_db no-undo.
define variable l_packing_order        like rcf_packing_order no-undo.
define variable l_seq_per_container    like rcf_seq_per_container no-undo.
define variable l_check_seq_tol        like rcf_check_seq_tol no-undo.
define variable l_max_tol              like rcf_max_tol no-undo.
define variable l_time_hr              as integer no-undo.
define variable l_time_min             as integer no-undo.
define variable l_int_cust_seq         as integer no-undo.
define variable l_custseq              like rcsd_cust_seq no-undo.

/* Following variables need undo capability because of deletes */
define variable prev_recid    as recid.
define variable current_recid as recid.
define variable rcsd_recid    as recid.

define buffer bf_active  for rcs_mstr.
define buffer b_rcsd_det for rcsd_det.

/* FRAME A: SELECTION FORM */


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
rcs_shipfrom      colon 25
   l_sitename        no-label
   rcs_shipto        colon 25
   l_shipname        no-label
   rcs_rlse_id       colon 25
   rcs_active        colon 70
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* FRAME B: SELECTION FORM */

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
rcs_cr_date       colon 25
   rcs_cr_time       no-label
   rcs_cumulative    colon 25
   rcs_packing_order colon 25
   rcs_seq_per_container
   colon 25
   rcs_check_seq_tol colon 25
   rcs_max_tol       colon 25
   rcs_date_type     colon 25
   rcs_active_start  colon 25
   rcs_active_end    colon 25
 SKIP(.4)  /*GUI*/
with frame b side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-b-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
 RECT-FRAME-LABEL:HIDDEN in frame b = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame b =
  FRAME b:HEIGHT-PIXELS - RECT-FRAME:Y in frame b - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME b = FRAME b:WIDTH-CHARS - .5.  /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame b:handle).

/* FRAME C: SELECTION FORM */

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1.4 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1   COLUMN 3 NO-LABEL
 SKIP(.1)  /*GUI*/
rcsd_date            colon 25
   rcsd_time
   rcsd_cust_job        colon 25
   rcsd_cust_seq        colon 25
   rcsd_order           colon 25
   rcsd_line            colon 45
   pt_um                colon 72
   rcsd_part            colon 25
   pt_desc1             no-label
   rcsd_cust_po         colon 25
   rcsd_custref         colon 25 label "Line Item Customer Ref"
   rcsd_modelyr         colon 72
   rcsd_cust_ref        colon 25
   rcsd_dock            colon 25
   rcsd_picked          colon 72
   rcsd_line_feed       colon 25
   rcsd_x_referenced    colon 72 label "X-Ref"
   skip (1)
   rcsd_discr_qty       colon 25
   rcsd_cum_qty         colon 60
   rcsd_cust_part       colon 25
   rcsd_cust_build_date colon 25
   rcsd_status          colon 45
   rcsd_deleted          colon 65 label "Delete"
 SKIP(.4)  /*GUI*/
with frame c side-labels width 80 attr-space
     NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-c-title AS CHARACTER.
 F-c-title = (getFrameTitle("SEQUENCE_DETAIL_DATA",26)).
 RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
 RECT-FRAME-LABEL:WIDTH-PIXELS in frame c =
  FONT-TABLE:GET-TEXT-WIDTH-PIXELS(
  RECT-FRAME-LABEL:SCREEN-VALUE in frame c + " ", RECT-FRAME-LABEL:FONT).
 RECT-FRAME:HEIGHT-PIXELS in frame c =
  FRAME c:HEIGHT-PIXELS - RECT-FRAME:Y in frame c - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME c = FRAME c:WIDTH-CHARS - .5. /*GUI*/


/* SET EXTERNAL LABELS */
setFrameLabels(frame c:handle).

on leave of rcs_shipfrom do:
   assign
      ship-param1 = input rcs_shipfrom.

   run get_site_name
      (input (input rcs_shipfrom), output l_sitename).
   display l_sitename with frame a.

        
   do on error undo, leave:
   run q-leave in global-drop-down-utilities.
   end.
   run q-set-window-recid in global-drop-down-utilities.
   if return-value = "error" then return no-apply.   

end.  /* on leave of rcs_shipfrom */

on leave of rcs_shipto do:
   assign
      ship-param2 = input rcs_shipto.

   run get_ship_name
      (input (input rcs_shipto), output l_shipname).
   display l_shipname with frame a.

        
   do on error undo, leave:
   run q-leave in global-drop-down-utilities.
   end.
   run q-set-window-recid in global-drop-down-utilities.
   if return-value = "error" then return no-apply.   

end.  /* on leave of rcs_shipto */

on entry of rcs_rlse_id do:
   {gpbrparm.i &browse=rclu104.p &parm=c-brparm1 &val=ship-param1}
   {gpbrparm.i &browse=rclu104.p &parm=c-brparm2 &val=ship-param2}
end.

/* DISPLAY */

view frame a.
view frame b.

/* PROMPT-FOR KEYS */
mainloop:
repeat with frame a:
/*GUI*/ if global-beam-me-up then undo, leave.

   prompt-for
      rcs_shipfrom
      rcs_shipto
      rcs_rlse_id
      with frame a
   editing:

      {mfnp12.i rcs_mstr
         rcs_index2
         "rcs_shipfrom <> ''"
         rcs_shipfrom
         "input frame a rcs_shipfrom"
         rcs_shipto
         "input frame a rcs_shipto"
         rcs_rlse_id
         "input frame a rcs_rlse_id"
         rcs_active
         true
         }

      if recno <> ? then do:
         run get_site_name
            (input rcs_shipfrom, output l_sitename).

         run get_ship_name
            (input rcs_shipto, output l_shipname).
         display
            rcs_shipfrom
            l_sitename
            rcs_active
            rcs_shipto
            l_shipname
            rcs_rlse_id
         with frame a.

         display
            rcs_cr_date
            rcs_cr_time
            rcs_cumulative
            rcs_packing_order
            rcs_seq_per_container
            rcs_check_seq_tol
            rcs_max_tol
            rcs_date_type
            rcs_active_start
            rcs_active_end
         with frame b.
         assign
            ship-param1 = rcs_shipfrom
            ship-param2 = rcs_shipto.

      end. /* if recno <> ? */

   end. /* prompt-for editing */

   assign
      l_shipfrom = input frame a rcs_shipfrom
      l_shipto   = input frame a rcs_shipto
      l_rlse_id  = input frame a rcs_rlse_id
      .

   /* VALIDATE SHIPFROM */
   run val_shipfrom
      (input l_shipfrom,
       output mc-error-number,
       output l_site_db).

   if mc-error-number > 0 then do:
      if mc-error-number = 2510 then do:
         /* DATABASE NOT AVAILABLE */
         {pxmsg.i &MSGNUM=2510 &ERRORLEVEL=4 &MSGARG1="l_site_db"}
      end.
      else
         run display_std_msg (input mc-error-number, input 3).

      next-prompt rcs_shipfrom with frame a.
      undo, retry.
   end.

   /* VALIDATE SHIPTO */

   if l_shipto = "" then do:
      /* BLANK NOT ALLOWED */
      run display_std_msg (input 40, input 3).
      next-prompt rcs_shipto with frame a.
      undo, retry.
   end.

   run validate_shipto
      (input l_shipto,
      output l_err_stat).

   if l_err_stat then do:
      next-prompt rcs_shipto with frame a.
      undo, retry.
   end.

   /*VALIDATE THAT A SCHEDULED ORDER EXISTS */

   for first scx_ref where
      scx_type = 1 and
      scx_shipfrom = l_shipfrom and
      scx_shipto   = l_shipto no-lock:
   end.
/*GUI*/ if global-beam-me-up then undo, leave.

   if not available scx_ref then do:
      /* SCHEDULED ORDER DOES NOT EXIST */
      run display_std_msg (input 2964, input 3).
      next-prompt rcs_shipfrom with frame a.
      undo, retry.
   end.

   /* VALIDATE DOCUMENT ID */

   if l_rlse_id = "" then do:
      for first rcs_mstr
         where rcs_shipfrom = l_shipfrom
           and rcs_shipto = l_shipto
           and rcs_active no-lock:
         l_rlse_id = rcs_rlse_id.
         display rcs_rlse_id with frame a.
      end.

      if not available rcs_mstr then do:
         /* BLANK NOT ALLOWED */
         run display_std_msg (input 40, input 3).
         next-prompt rcs_rlse_id with frame a.
         undo, retry.
      end.
   end.

   /* ADD, MODIFY, DELETE */

   for first rcs_mstr where
      rcs_shipfrom = l_shipfrom    and
      rcs_shipto   = l_shipto      and
      rcs_rlse_id  = l_rlse_id exclusive-lock:

   end.

   if not available rcs_mstr then do:
      copy-yn = no.
      /* ADDING NEW RECORD */
      run display_std_msg (input 1, input 1).

      for first rcf_ctrl no-lock:
      end.
      if not available (rcf_ctrl) then
         create rcf_ctrl.

      for first rcc_mstr where
         rcc_addr = l_shipto no-lock:
      end.
      if available (rcc_mstr) then
      assign
         l_packing_order     = rcc_packing_order
         l_seq_per_container = rcc_seq_per_container
         l_check_seq_tol     = rcc_check_seq_tol
         l_max_tol           = rcc_max_tol.
      else
      assign
         l_packing_order     = rcf_packing_order
         l_seq_per_container = rcf_seq_per_container
         l_check_seq_tol     = rcf_check_seq_tol
         l_max_tol           = rcf_max_tol.

      create rcs_mstr.
      assign
         rcs_shipfrom          =   l_shipfrom
         rcs_shipto            =   l_shipto
         rcs_rlse_id           =   l_rlse_id
         rcs_active_start      =   today
         rcs_cr_time           =   string(time,"HH:MM:SS")
         rcs_cr_date           =   today
         rcs_packing_order     =   l_packing_order
         rcs_seq_per_container =   l_seq_per_container
         rcs_check_seq_tol     =   l_check_seq_tol
         rcs_max_tol           =   l_max_tol
         rcs_mod_date          =   today
         rcs_mod_userid        =   global_userid
         rcs_mod_pgm           =   program-name(1)
         .

      if recid(rcs_mstr) = -1 then .
      current_recid = recid(rcs_mstr).

      /* CHECK TO SEE IF THERE IS AN ACTIVE SCHEDULE */
      for first rcs_mstr where
         rcs_shipfrom = l_shipfrom    and
         rcs_shipto   = l_shipto      and
         rcs_active
      no-lock:
      end.
      if available rcs_mstr then do:
         /* COPY DATA FROM ACTIVE SCHEDULE? */
         run get_action_prompt
            (input 2965,
            output copy-yn).

         if copy-yn = yes then
            run copy_active_schedule
               (input current_recid,
                input l_shipfrom,
                input l_shipto,
                input l_rlse_id).
      end. /*IF AVAILABLE RCS_MSTR*/

      for first rcs_mstr where
         recid(rcs_mstr) = current_recid
      exclusive-lock:
      end.

   end. /* if not available rcs_mstr */

   display
      l_sitename
      rcs_active
      l_shipname
   with frame a.

   current_recid = recid(rcs_mstr).

   if not rcs_active and not copy-yn then do for bf_active:
      for first bf_active no-lock
         where rcs_shipfrom = l_shipfrom
           and rcs_shipto = l_shipto
           and rcs_active:
      end.
      if available bf_active then do:
         /* NOT ACTIVE RELEASE, ACTIVE RLSE IS .. */
         {pxmsg.i &MSGNUM=6005 &ERRORLEVEL=2 &MSGARG1=rcs_rlse_id}
      end.
   end.
   else
   if rcs_active and not copy-yn then
      /* MODIFYING THE ACTIVE RELEASE */
      run display_std_msg (input 6006, input 2).

   display
      rcs_cr_date
      rcs_cr_time
      rcs_cumulative
      rcs_packing_order
      rcs_seq_per_container
      rcs_check_seq_tol
      rcs_max_tol
      rcs_date_type
      rcs_active_start
      rcs_active_end
   with frame b.

   ststatus = stline[2].
   status input ststatus.

   assign
      del-yn = no
      copy-yn = no.

   setloop1:
   do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

      set
         rcs_cumulative
         rcs_packing_order
         rcs_seq_per_container
         rcs_check_seq_tol
         rcs_max_tol
         rcs_date_type
         rcs_active_start
         rcs_active_end
         go-on("F5" "CTRL-D")
      with frame b.

      /* DELETE SEQUENCE MASTER/DETAIL */

      if lastkey = keycode("F5") or lastkey = keycode("CTRL-D")
      then do:
         del-yn = no.
         run get_action_prompt
            (input 11,
            output del-yn). /* CONFIRM DELETE */

         if del-yn = no then
            undo, retry.

         else do:
            for each rcsd_det exclusive-lock where
                  rcsd_shipfrom = rcs_shipfrom   and
                  rcsd_shipto   = rcs_shipto     and
                  rcsd_rlse_id  = rcs_rlse_id:

               delete rcsd_det.

            end.

            for each rcsx_ref exclusive-lock where
                  rcsx_shipfrom         = rcs_shipfrom and
                  rcsx_shipto           = rcs_shipto   and
                  (rcsx_shipped_rlse_id = rcs_rlse_id or
                   rcsx_rlse_id         = rcs_rlse_id):

               delete rcsx_ref.

            end.

            delete rcs_mstr.
            clear frame a.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
            clear frame b.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame b = F-b-title.
            clear frame c.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
            del-yn = no.
            next mainloop.

         end. /* else do: */
      end. /* if lastkey = keycode ... */

      if rcs_active_start <> ? and
         (rcs_active_end < rcs_active_start) then do:
         /* START DATE MUST BE PRIOR TO END DATE*/
         run display_std_msg (input 4, input 3).
         next-prompt rcs_active_end with frame b.
         undo, retry.
      end.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* setloop1 */

   hide frame b.

   setloop2a:
   repeat with frame c:
/*GUI*/ if global-beam-me-up then undo, leave.

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         prompt-for
            rcsd_date
            with frame c
         editing:

            {mfnp05.i rcsd_det rcsd_index2
               "rcsd_shipfrom = rcs_shipfrom and
                rcsd_shipto   = rcs_shipto   and
                rcsd_rlse_id  = rcs_rlse_id"
               rcsd_date
               "input frame c rcsd_date"}

            if recno <> ? then do:
               for first pt_mstr
                  fields ( pt_desc1 pt_um ) where
                  pt_part = rcsd_part no-lock:
               end.

               display
                  rcsd_date
                  rcsd_time
                  rcsd_cust_job
                  rcsd_cust_seq
                  rcsd_order
                  rcsd_line
                  pt_um           when (available pt_mstr)
                  ""              when (not available pt_mstr)
                  @ pt_um
                  rcsd_part
                  pt_desc1        when (available pt_mstr)
                  ""              when (not available pt_mstr)
                  @ pt_desc1
                  rcsd_cust_po
                  rcsd_custref
                  rcsd_modelyr
                  rcsd_cust_ref
                  rcsd_dock
                  rcsd_picked
                  rcsd_line_feed
                  rcsd_x_referenced
                  rcsd_discr_qty
                  rcsd_cum_qty    when (rcs_cumulative)
                  0               when (not rcs_cumulative)
                  @ rcsd_cum_qty
                  rcsd_cust_part
                  rcsd_cust_build_date
                  rcsd_status
                  rcsd_deleted
               with frame c.
               prev_recid = recid(rcsd_det).
            end. /* if recno <> ? */

         end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* prompt-for */

         /* VALIDATE DATE */
         if input rcsd_date = "" then do:
            /*DATE REQUIRED*/
            run display_std_msg (input 711, input 3).
            next-prompt rcsd_date with frame c.
            undo, retry.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* setloop2a - do on error, undo retry */

      setloop2b:

      do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

         prompt-for
            rcsd_time
         with frame c.

         if input rcsd_time <> "" then do:
            assign
               l_time_hr = integer(substring(input rcsd_time,1,2))
               l_time_min = integer(substring(input rcsd_time,3,4)).

            if l_time_hr > 24 or
               l_time_min > 59
            then do:
               /* Invalid detail time */
               run display_std_msg (input 8242, input 3).
               undo,retry.
            end.

         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.
  /* setloop2b */

      setloop2c:
      repeat with frame c:
/*GUI*/ if global-beam-me-up then undo, leave.

         do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

            prompt-for
               rcsd_cust_job
               rcsd_cust_seq
               rcsd_order
               rcsd_line
               rcsd_part
               rcsd_cust_po
               rcsd_custref
               rcsd_modelyr
               rcsd_cust_ref
               rcsd_dock
               rcsd_line_feed
               with frame c
            editing:

               {mfnp15.i rcsd_det rcsd_index2
                  "rcsd_shipfrom = rcs_shipfrom and
                    rcsd_shipto   = rcs_shipto   and
                    rcsd_rlse_id  = rcs_rlse_id"
                  rcsd_cust_job
                  "input frame c rcsd_cust_job"
                  rcsd_cust_seq
                  "input frame c rcsd_cust_seq"
                  rcsd_part
                  "input frame c rcsd_part"
                  rcsd_cust_ref
                  "input frame c rcsd_cust_ref"
                  rcsd_date
                  "input frame c rcsd_date"
                  rcsd_time
                  "input frame c rcsd_time"
                  rcsd_cust_po
                  "input frame c rcsd_cust_po"}

               if recno <> ? then do:
                  for first pt_mstr
                     fields ( pt_desc1 pt_um ) where
                     pt_part = rcsd_part no-lock:
                  end.

                  display
                     rcsd_date
                     rcsd_time
                     rcsd_cust_job
                     rcsd_cust_seq
                     rcsd_order
                     rcsd_line
                     pt_um           when (available pt_mstr)
                     ""              when (not available pt_mstr)
                     @ pt_um
                     rcsd_part
                     pt_desc1        when (available pt_mstr)
                     ""              when (not available pt_mstr)
                     @ pt_desc1
                     rcsd_cust_po
                     rcsd_custref
                     rcsd_modelyr
                     rcsd_cust_ref
                     rcsd_dock
                     rcsd_picked
                     rcsd_line_feed
                     rcsd_x_referenced
                     rcsd_discr_qty
                     rcsd_cum_qty    when (rcs_cumulative)
                     0               when (not rcs_cumulative)
                     @ rcsd_cum_qty
                     rcsd_cust_part
                     rcsd_cust_build_date
                     rcsd_status
                     rcsd_deleted
                  with frame c.
                  prev_recid = recid(rcsd_det).
               end. /* if recno <> ? */

            end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* prompt-for..editing */

            l_tmp_po = input rcsd_cust_po.

            /* *** VALIDATION AREA *** */

            /*** VALIDATE CUSTOMER SEQUENCE NUMBER ***/
            if input rcsd_cust_seq = "" then do:
               /* BLANK NOT ALLOWED */
               run display_std_msg (input 40, input 3).
               next-prompt rcsd_cust_seq with frame c.
               undo, retry.
            end.

            if input rcsd_order <> "" and
               input rcsd_line  <> "" and
               input rcsd_part  =  "" then do:
               for first scx_ref
                  where scx_type = 1
                    and scx_shipfrom = rcs_shipfrom
                    and scx_shipto = rcs_shipto
                    and scx_order = input rcsd_order
                    and scx_line = input rcsd_line
               no-lock:
               end.

               if available (scx_ref) and
                  input rcsd_part = "" and
                  input rcsd_cust_po   = ""
               then
                  display
                     scx_part @ rcsd_part
                     scx_po   @ rcsd_cust_po
                  with frame c.
            end.
/*GUI*/ if global-beam-me-up then undo, leave.


            /**** VALIDATE PART VALIDATION ****/
            if input rcsd_part = "" then do:
               /* BLANK NOT ALLOWED */
               run display_std_msg (input 40, input 3).
               next-prompt rcsd_part with frame c.
               undo, retry.
            end.

            assign
               l_cust_part = ""
               l_part  = input frame c rcsd_part
               .

            /* SEARCH CUSTOMER ITEM/ ITEM MASTER */
            {gprun.i ""sopart.p""
               "(input l_shipto,
                 input """",
                 input-output l_part,
                 output l_cust_part)"}
/*GUI*/ if global-beam-me-up then undo, leave.


            for first pt_mstr
               fields ( pt_desc1 pt_um )
               where pt_part = l_part no-lock:
               display
                  pt_desc1
                  pt_um
               with frame c.
            end. /* FOR FIRST PT_MSTR */

            if not available pt_mstr then do:
               /* ITEM NUMBER DOES NOT EXIST */
               run display_std_msg (input 16, input 3).
               next-prompt rcsd_part with frame c.
               undo, retry.
            end. /* IF NOT AVAILABLE PT_MSTR */

            /* IS l_part DIFFERENT FROM THE SCREEN VALUE? */
            if l_part <> input frame c rcsd_part then do:

               /* CUSTOMER ITEM # REPLACED BY # */
               {pxmsg.i &MSGNUM=56 &ERRORLEVEL=1
                        &MSGARG1="input frame c rcsd_part"
                        &MSGARG2=l_part}

               display l_part @ rcsd_part with frame c.

            end. /* IF L_PART <> RCSD_PART */

            /* IS THE PART ASSOCIATED WITH A SCHEDULED ORDER*/

            for first scx_ref where
               scx_type     = 1                  and
               scx_shipfrom = rcs_shipfrom       and
               scx_shipto   = rcs_shipto         and
               scx_part     = input rcsd_part    and
               scx_custref  = input rcsd_custref and
               scx_po       = input rcsd_cust_po and
               scx_modelyr  = input rcsd_modelyr
            no-lock:
            end.

            if not available scx_ref then do:
               /*SCHEDULED ORDER DETAIL DOES NOT EXIST*/
               run display_std_msg (input 8104, input 3).
               next-prompt rcsd_cust_po with frame c.
               undo, retry.
            end.

            for first so_mstr no-lock
               where so_nbr = scx_order:
            if not so_seq_order then do:
               /*SCHEDULED ORDER # IS NOT SEQUENCED */
               {pxmsg.i &MSGNUM=3073 &ERRORLEVEL=3
                        &MSGARG1=scx_order}
               next-prompt rcsd_cust_po with frame c.
               next setloop2c.
               end.
            end.

            /**** VALIDATE CUSTOMER REFERENCE ****/
            if input rcsd_cust_ref = "" then do:
               /* BLANK NOT ALLOWED */
               run display_std_msg (input 40, input 3).
               next-prompt rcsd_cust_ref with frame c.
               undo, retry.
            end.

            /**** DETERMINE TO ADD OR MODIFY ****/
            for first rcsd_det where
               rcsd_shipfrom = rcs_shipfrom        and
               rcsd_shipto   = rcs_shipto          and
               rcsd_rlse_id  = rcs_rlse_id         and
               rcsd_cust_job = input rcsd_cust_job and
               rcsd_cust_seq = input rcsd_cust_seq and
               rcsd_part     = l_part              and
               rcsd_date     = input rcsd_date     and
               rcsd_time     = input rcsd_time     and
               rcsd_custref  = input rcsd_custref  and
               rcsd_modelyr  = input rcsd_modelyr  and
               rcsd_cust_ref = input rcsd_cust_ref and
               rcsd_dock     = input rcsd_dock     and
               rcsd_line_feed = input rcsd_line_feed
            exclusive-lock:

            if prev_recid = ? then
               prev_recid = recid(rcsd_det).
            rcsd_cust_po = l_tmp_po.

            end. /* for first rcsd_det */

            if not available rcsd_det then do:

               /* DOUBLE-CHECK TO ENSURE CUST-REF ISN'T DUPLICATED */
               for first rcsd_det where
                  rcsd_shipfrom  = rcs_shipfrom         and
                  rcsd_shipto    = rcs_shipto           and
                  rcsd_rlse_id   = rcs_rlse_id          and
                  rcsd_part      = l_part               and
                  rcsd_cust_ref  = input rcsd_cust_ref  and
                  rcsd_dock      = input rcsd_dock      and
                  rcsd_line_feed = input rcsd_line_feed and
                  (not rcsd_deleted)
               no-lock:
               end.

               if available rcsd_det then do:
                  /*SEQUENCE ALREADY EXISTS FOR REFERENCE: */
                  {pxmsg.i &MSGNUM=3334 &ERRORLEVEL=3
                           &MSGARG1=rcsd_cust_ref}
                  next-prompt rcsd_cust_job with frame c.
                  undo, retry.
               end.  /* if available rcsd_det */
               l_custseq = input rcsd_cust_seq.
               /* CHECK IF SEQ SKIPPED */
               if rcs_check_seq_tol and
                  not can-find(first b_rcsd_det
                  where b_rcsd_det.rcsd_rlse_id = rcs_rlse_id
                    and b_rcsd_det.rcsd_shipfrom = rcs_shipfrom
                    and b_rcsd_det.rcsd_shipto   = rcs_shipto
                    and b_rcsd_det.rcsd_cust_seq = l_custseq)
               then do:
                  l_int_cust_seq = integer(l_custseq) no-error.

                  if not ERROR-STATUS:ERROR then do:
                     run check_if_seq_skipped
                       (input l_int_cust_seq,
                        input rcs_shipto,
                        input rcs_shipfrom,
                        input rcs_rlse_id,
                        input rcs_max_tol,
                        output l_err_stat).
                     if l_err_stat then do.
                        next-prompt rcsd_cust_seq with frame c.
                        undo, retry.
                     end.
                  end.
                  else
                     /*Seq alphanumeric, unable to check seq tol*/
                     run display_std_msg (input 3399, input 2).
               end. /* IF RCS_CHECK_SEQ_TOL */

               /* ADDING NEW RECORD */
               run display_std_msg (input 1, input 1).
               create rcsd_det.
               assign
                  rcsd_shipfrom   = rcs_shipfrom
                  rcsd_shipto     = rcs_shipto
                  rcsd_rlse_id    = rcs_rlse_id
                  rcsd_cust_job   = input rcsd_cust_job
                  rcsd_cust_seq   = input rcsd_cust_seq
                  rcsd_cust_po    = input rcsd_cust_po
                  rcsd_part       = l_part
                  rcsd_cust_part  = l_cust_part
                  rcsd_order      = scx_order
                  rcsd_line       = scx_line
                  rcsd_part       = input rcsd_part
                  rcsd_time       = input rcsd_time
                  rcsd_date       = input rcsd_date
                  rcsd_custref    = input rcsd_custref
                  rcsd_modelyr    = input rcsd_modelyr
                  rcsd_cust_ref   = input rcsd_cust_ref
                  rcsd_dock       = input rcsd_dock
                  rcsd_line_feed  = input rcsd_line_feed
                  rcsd_mod_userid = global_userid
                  rcsd_mod_date   = today
                  rcsd_mod_pgm    = program-name(1)
                  .

               if recid(rcsd_det) = -1 then .

            end. /* if not available rcsd_det */

            if rcsd_recid <> ? then
            for first rcsd_det where
               recid(rcsd_det) = rcsd_recid
            exclusive-lock:
            end.

            display
               rcsd_date
               rcsd_time
               rcsd_cust_job
               rcsd_cust_seq
               rcsd_order
               rcsd_line
               pt_um           when (available pt_mstr)
               ""              when (not available pt_mstr)
               @ pt_um
               rcsd_part
               pt_desc1        when (available pt_mstr)
               ""              when (not available pt_mstr)
               @ pt_desc1
               rcsd_cust_po
               rcsd_custref
               rcsd_modelyr
               rcsd_cust_ref
               rcsd_dock
               rcsd_picked
               rcsd_line_feed
               rcsd_x_referenced
               rcsd_discr_qty
               rcsd_cum_qty    when (rcs_cumulative)
               0               when (not rcs_cumulative)
               @ rcsd_cum_qty
               rcsd_cust_part
               rcsd_cust_build_date
            with frame c.

            assign
               ststatus           = stline[2]
               l_update_cum_qty   = (if rcs_cumulative then yes
                                     else no)
               l_update_discr_qty = (if not rcs_cumulative then yes
                                     else no)
               .

            if rcsd_picked or rcsd_x_referenced or rcsd_deleted then
            do:

               if rcsd_picked or rcsd_x_referenced then
                  /* SEQUENCE ALREADY SELECTED FOR SHIPMENT.  */
                  /* UPDATES NOT ALLOWED.                     */
                  run display_std_msg (input 3319, input 4).

               if rcsd_deleted then
                  /* SEQUENCE DELETED.  UPDATES NOT ALLOWED.  */
                  run display_std_msg (input 3403, input 4).

            end.  /* if rcsd_picked */
            else do:

               if l_update_cum_qty then
                  l_old_qty = rcsd_cum_qty.
               else
                  l_old_qty = rcsd_discr_qty.

               display
                  rcsd_discr_qty      when (l_update_discr_qty)
                  rcsd_cum_qty        when (l_update_cum_qty)
                  rcsd_cust_build_date
                  rcsd_status
                  rcsd_deleted
               with frame c.

               setloop3:
               do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

                  set
                     rcsd_discr_qty      when (l_update_discr_qty)
                     rcsd_cum_qty        when (l_update_cum_qty)
                     rcsd_cust_build_date
                     rcsd_status
                     rcsd_deleted
                  with frame c.

                  /** VALIDATION AREA LOOP 3 ** BEGIN **/

                  /*VALIDATE DISCRETE QUANTITY*/
                  if l_update_discr_qty and
                     l_old_qty <> input rcsd_discr_qty
                  then do:
                     rcsd_recid = recid(rcsd_det).
                     if input rcsd_discr_qty < 0 then do:
                        /*QUANTITY MUST BE >= 0 */
                        run display_std_msg (input 2969, input 3).
                        next-prompt rcsd_discr_qty with frame c.
                        undo, retry.
                     end.

                     for first rcsd_det exclusive-lock
                        where recid(rcsd_det) = rcsd_recid:
                     end.
                     assign
                        rcsd_recid = ?
                        prev_recid = ?.
                     display rcsd_cum_qty with frame c.
                  end.
/*GUI*/ if global-beam-me-up then undo, leave.


                  /*VALIDATE CUM QUANTITY*/
                  if l_update_cum_qty and
                     l_old_qty <> input rcsd_cum_qty
                  then do:
                     rcsd_recid = recid(rcsd_det).
                     if input rcsd_cum_qty < 0 then do:
                        /*QUANTITY MUST BE >= 0 */
                        run display_std_msg (input 2969, input 3).
                        next-prompt rcsd_cum_qty with frame c.
                        undo, retry.
                     end.

                     run determine_prev_cum_qty
                       (input rcsd_recid,
                        input l_shipfrom,
                        input l_shipto,
                        input l_rlse_id,
                        input (input rcsd_part),
                        input rcsd_cust_job,
                        input rcsd_cust_seq,
                        input rcsd_cust_po,
                        input rcsd_date,
                        input rcsd_time,
                        output l_prev_cum_qty).

                     if l_prev_cum_qty >= rcsd_cum_qty then do:

                        /*QUANTITY MUST BE > PREV CUM QTY*/
                        {pxmsg.i &MSGNUM=2970 &ERRORLEVEL=3
                                 &MSGARG1=l_prev_cum_qty}
                        next-prompt rcsd_cum_qty with frame c.
                        undo, retry.
                     end.

                     run update_qty
                       (input rcsd_recid,
                        input l_shipfrom,
                        input l_shipto,
                        input l_rlse_id,
                        input (input rcsd_part),
                        input rcsd_cust_job,
                        input rcsd_cust_seq,
                        input rcsd_cust_po,
                        input l_prev_cum_qty,
                        input false
                        ).
                     for first rcsd_det exclusive-lock
                        where recid(rcsd_det) = rcsd_recid:
                     end.
                     assign
                        rcsd_recid = ?
                        prev_recid = ?.
                     display rcsd_discr_qty with frame c.

                  end.  /* if l_update_cum_qty and ... */

                  /** VALIDATION AREA LOOP 3 ** END **/

               end. /*SETLOOP3*/
            end. /*IF NOT RCSD_PICKED*/

            /* GET THE ORDER/LINE TO UPDATE THE SCHEDULE CHANGE FLAG */
            for first sod_det where
               sod_nbr = scx_order and
               sod_line = scx_line:
               sod_sched_chgd = yes.
            end.

            prev_recid = recid(rcsd_det).

         end.  /* setloop2c - do on error undo, retry */

      end.  /* setloop2c repeat */

   end.  /* setloop2a repeat */

   clear frame c.
/*GUI*/ RECT-FRAME-LABEL:SCREEN-VALUE in frame c = F-c-title.
   hide frame c.
   view frame a.
   view frame b.

   if not rcs_active then do:
      current_recid = recid(rcs_mstr).
      l_make_active-yn = no.

      run get_action_prompt
         (input 6001,
         output l_make_active-yn). /*MAKE THIS SCHEDULE ACTIVE?*/

      if l_make_active-yn then do:
         for first rcs_mstr where
            rcs_shipfrom = l_shipfrom    and
            rcs_shipto   = l_shipto      and
            rcs_active exclusive-lock:
            assign
               rcs_active     = no
               rcs_active_end = today
               rcs_mod_userid = global_userid
               rcs_mod_date   = today
               rcs_mod_pgm    = program-name(1).
         end.

         for first rcs_mstr where recid(rcs_mstr) = current_recid
         exclusive-lock:
         end.

         assign
            rcs_active      = yes
            rcs_active_date = today
            rcs_active_end  = ?
            rcs_mod_userid  = global_userid
            rcs_mod_date    = today
            rcs_mod_pgm     = program-name(1).

      end. /* IF l_make_active-yn*/

   end. /*IF NOT RCS_ACTIVE*/
   display rcs_active with frame a.
   display rcs_active_start with frame b.
end. /* mainloop */

PROCEDURE copy_active_schedule:
   define input parameter ip_current_recid as recid.
   define input parameter ip_shipfrom like rcs_shipfrom no-undo.
   define input parameter ip_shipto like rcs_shipto no-undo.
   define input parameter ip_id like rcs_rlse_id no-undo.

   define variable l_create_xref_yn like mfc_logical no-undo
      initial no.

   define buffer bf_mstr for rcs_mstr.
   define buffer bf_det  for rcsd_det.

   /* CREATE CROSS-REFERENCE RECORD TO PREVIOUS RELEASE?   */
   run get_action_prompt
      (input 3074,
       output l_create_xref_yn ).

   /* GET ACTIVE RELEASE   */
   for first bf_mstr where
      bf_mstr.rcs_shipfrom = ip_shipfrom and
      bf_mstr.rcs_shipto   = ip_shipto   and
      bf_mstr.rcs_active no-lock:
   end.
   for first rcs_mstr where recid(rcs_mstr) = ip_current_recid
   exclusive-lock:
   assign
      rcs_mstr.rcs_cumulative        = bf_mstr.rcs_cumulative
      rcs_mstr.rcs_packing_order     = bf_mstr.rcs_packing_order
      rcs_mstr.rcs_seq_per_container = bf_mstr.rcs_seq_per_container
      rcs_mstr.rcs_check_seq_tol     = bf_mstr.rcs_check_seq_tol
      rcs_mstr.rcs_max_tol           = bf_mstr.rcs_max_tol
      rcs_mstr.rcs_date_type         = bf_mstr.rcs_date_type
      rcs_mstr.rcs_active_start      = bf_mstr.rcs_active_start
      .
   for each bf_det where
         bf_det.rcsd_shipfrom = ip_shipfrom and
         bf_det.rcsd_shipto   = ip_shipto   and
         bf_det.rcsd_rlse_id  = bf_mstr.rcs_rlse_id and
         not bf_det.rcsd_deleted
      no-lock:

      /* COPY DETAIL RECORDS   */
      create rcsd_det.
      assign
         rcsd_det.rcsd_shipfrom        = ip_shipfrom
         rcsd_det.rcsd_shipto          = ip_shipto
         rcsd_det.rcsd_rlse_id         = ip_id
         rcsd_det.rcsd_cust_job        = bf_det.rcsd_cust_job
         rcsd_det.rcsd_cust_seq        = bf_det.rcsd_cust_seq
         rcsd_det.rcsd_part            = bf_det.rcsd_part
         rcsd_det.rcsd_cust_part       = bf_det.rcsd_cust_part
         rcsd_det.rcsd_cust_po         = bf_det.rcsd_cust_po
         rcsd_det.rcsd_date            = bf_det.rcsd_date
         rcsd_det.rcsd_time            = bf_det.rcsd_time
         rcsd_det.rcsd_discr_qty       = bf_det.rcsd_discr_qty
         rcsd_det.rcsd_cum_qty         = bf_det.rcsd_cum_qty
         rcsd_det.rcsd_order           = bf_det.rcsd_order
         rcsd_det.rcsd_line            = bf_det.rcsd_line
         rcsd_det.rcsd_dock            = bf_det.rcsd_dock
         rcsd_det.rcsd_line_feed       = bf_det.rcsd_line_feed
         rcsd_det.rcsd_custref         = bf_det.rcsd_custref
         rcsd_det.rcsd_modelyr         = bf_det.rcsd_modelyr
         rcsd_det.rcsd_cust_ref        = bf_det.rcsd_cust_ref
         rcsd_det.rcsd_status          = bf_det.rcsd_status
         rcsd_det.rcsd_deleted         = bf_det.rcsd_deleted
         rcsd_det.rcsd_cust_build_date = bf_det.rcsd_cust_build_date
         rcsd_det.rcsd_derived_rlse_id = bf_det.rcsd_rlse_id
         rcsd_det.rcsd_mod_userid      = global_userid
         rcsd_det.rcsd_mod_date        = today
         rcsd_det.rcsd_mod_pgm         = program-name(1)
         .
      if recid(rcsd_det) = -1 then .

      if (bf_det.rcsd_picked or bf_det.rcsd_x_referenced) and
         l_create_xref_yn
      then do:

         create rcsx_ref.
         assign
            rcsx_shipfrom          = ip_shipfrom
            rcsx_shipto            = ip_shipto
            rcsx_shipped_rlse_id   = bf_det.rcsd_rlse_id
            rcsx_shipped_cust_job  = bf_det.rcsd_cust_job
            rcsx_shipped_cust_seq  = bf_det.rcsd_cust_seq
            rcsx_shipped_part      = bf_det.rcsd_part
            rcsx_shipped_date      = bf_det.rcsd_date
            rcsx_shipped_time      = bf_det.rcsd_time
            rcsx_shipped_cust_ref  = bf_det.rcsd_cust_ref
            rcsx_shipped_dock      = bf_det.rcsd_dock
            rcsx_shipped_line_feed = bf_det.rcsd_line_feed
            rcsx_rlse_id           = rcsd_det.rcsd_rlse_id
            rcsx_cust_job          = rcsd_det.rcsd_cust_job
            rcsx_cust_seq          = rcsd_det.rcsd_cust_seq
            rcsx_part              = rcsd_det.rcsd_part
            rcsx_date              = rcsd_det.rcsd_date
            rcsx_time              = rcsd_det.rcsd_time
            rcsx_cust_ref          = rcsd_det.rcsd_cust_ref
            rcsx_dock              = rcsd_det.rcsd_dock
            rcsx_line_feed         = rcsd_det.rcsd_line_feed
            rcsx_mod_userid        = global_userid
            rcsx_mod_date          = today
            rcsx_mod_pgm           = program-name(1)
            .
         if recid(rcsx_ref) = -1 then .

         if bf_det.rcsd_picked then do:
            /* SET PICKED=NO AND X-REF=YES.     */
            /* NEW RECORD IS X-REFERENCED TO    */
            /* PICKED RECORD.                   */
            assign
               rcsd_det.rcsd_picked       = no
               rcsd_det.rcsd_x_referenced = yes.

            /* FIND PRE-SHIPPER/SHIPPER */

            for first abss_det where
               abss_shipfrom = ip_shipfrom and
               abss_shipto   = ip_shipto   and
               abss_rlse_id  = ip_id  and
               abss_cust_job = bf_det.rcsd_cust_job and
               abss_cust_seq = bf_det.rcsd_cust_seq and
               abss_part     = bf_det.rcsd_part     and
               abss_date     = bf_det.rcsd_date     and
               abss_time     = bf_det.rcsd_time     and
               abss_cust_ref = bf_det.rcsd_cust_ref and
               abss_dock     = bf_det.rcsd_dock     and
               abss_line_feed = bf_det.rcsd_line_feed
            no-lock:
            end.

            if available abss_det then
               assign
                  rcsx_picked = yes
                  rcsx_shipped =  (if abss_ship_id <> ""
                                   then yes
                                   else no).
            else
               assign
                  rcsx_picked = no
                  rcsx_shipped = no.

         end.  /* if bf_det.rcsd_picked */
         else
            assign
               rcsx_picked                = no
               rcsx_shipped               = no
               rcsd_det.rcsd_picked       = no
               rcsd_det.rcsd_x_referenced = yes.

      end.  /* if (bf_det.rcsd_picked or bf_det.rcsd_x_ref ...) */
      else
         /* RESET PICKED AND X-REFERENCED FLAGS */
         assign
            rcsd_det.rcsd_picked          = no
            rcsd_det.rcsd_x_referenced    = no.

   end. /*FOR EACH BF_DET*/
end. /*FOR FIRST RCS_MSTR*/

END PROCEDURE. /*copy_active_schedule*/

PROCEDURE get_ship_name:
   define input parameter ip_rcs_shipto like rcs_shipto no-undo.
   define output parameter op_shipname like ad_name no-undo.

   for first ad_mstr no-lock
      where ad_addr = ip_rcs_shipto:
   end.

   if available (ad_mstr) then
      op_shipname = ad_name.
   else
      op_shipname = "".
END PROCEDURE. /*get_ship_name*/

PROCEDURE get_site_name:
   define input parameter ip_from like rcs_shipfrom no-undo.
   define output parameter op_sitename like si_desc no-undo.

   for first si_mstr no-lock
      where si_site = ip_from:
   end.

   if available (si_mstr) then
      op_sitename = si_desc.
   else
      op_sitename = "".
END PROCEDURE. /*get_site_name*/

PROCEDURE update_qty:
   define input parameter ip_up_recid as recid no-undo.
   define input parameter ip_up_from like rcsd_shipfrom no-undo.
   define input parameter ip_up_to   like rcsd_shipto no-undo.
   define input parameter ip_up_id   like rcsd_rlse_id no-undo.
   define input parameter ip_up_part like rcsd_part no-undo.
   define input parameter ip_up_cust_job like rcsd_cust_job no-undo.
   define input parameter ip_up_cust_seq like rcsd_cust_seq no-undo.
   define input parameter ip_up_cust_po  like rcsd_cust_po no-undo.
   define input parameter ip_prev_qty like rcsd_cum_qty no-undo.
   define input parameter ip_up_discr like mfc_logical no-undo.

   define variable l_up_found like mfc_logical no-undo.
   define variable l_up_qty like rcsd_cum_qty no-undo.

   define buffer bf_rcsd_det for rcsd_det.

   assign
      l_up_found = no
      l_up_qty   = 0.

   for each bf_rcsd_det exclusive-lock
       where rcsd_shipfrom = ip_up_from
         and rcsd_shipto   = ip_up_to
         and rcsd_rlse_id  = ip_up_id
         and rcsd_part     = ip_up_part
         and rcsd_cust_po  = ip_up_cust_po
         and
         (rcsd_cust_job > ip_up_cust_job
         or
         (rcsd_cust_job = ip_up_cust_job  and
          rcsd_cust_seq >= ip_up_cust_seq))
       use-index rcsd_index2:

      if recid(bf_rcsd_det) = ip_up_recid then
         /* CUM */
         assign
            l_up_found = yes
            rcsd_discr_qty = rcsd_cum_qty - ip_prev_qty
            l_up_qty = rcsd_cum_qty.

      else
      if l_up_found then
         assign
            rcsd_cum_qty = l_up_qty + rcsd_discr_qty
            l_up_qty = rcsd_cum_qty.

   end. /* FOR EACH BF_RCSD_DET */

END PROCEDURE. /* update_qty */

PROCEDURE val_shipfrom:
   define input parameter ip_shipfrom like rcs_shipfrom no-undo.
   define output parameter op_error_number as integer no-undo.
   define output parameter op_db_name like si_db no-undo.

   assign
      op_db_name = ""
      op_error_number = 0.

   if ip_shipfrom = "" then do:
      op_error_number = 40.  /* BLANK NOT ALLOWED */
      return.
   end.

   for first si_mstr where si_site = ip_shipfrom no-lock:
   end.

   if not available si_mstr then do:
      op_error_number = 708. /* SITE DOES NOT EXIST */
      return.
   end.

   {gprun.i ""gpsiver.p""
      "(input ip_shipfrom, input ?, output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if return_int = 0 then do:
      op_error_number = 725.  /* USER DOES NOT HAVE ACCESS TO SITE */
      return.
   end.

   if si_db <> global_db
      and not connected(si_db) then do:
      assign
         op_db_name = si_db
         op_error_number = 2510. /* DATABASE NOT CONNECTED */
      return.
   end.

END PROCEDURE. /*val_shipfrom*/

PROCEDURE get_action_prompt:
   define input parameter msgnbr as integer no-undo.
   define output parameter op_yn like mfc_logical no-undo.

   define variable y-n like mfc_logical no-undo.
   assign
      op_yn = no
      y-n   = no.
   {pxmsg.i &MSGNUM=msgnbr &ERRORLEVEL=1 &CONFIRM=y-n}

   op_yn = y-n.
END PROCEDURE. /*get_action_prompt */

PROCEDURE display_std_msg:
   define input parameter ip-msg-nbr as integer no-undo.
   define input parameter ip-severity as integer no-undo.

   {pxmsg.i &MSGNUM=ip-msg-nbr &ERRORLEVEL=ip-severity}

END PROCEDURE. /* display_std_msg */

PROCEDURE validate_shipto:
   /* SIMILAR TO rcshhdr.i, BUT WEB-ENABLED AND W/O EXTRA CODE */
   define input  parameter shipto like abs_shipto no-undo.
   define output parameter err as logical no-undo.

   define variable addr like ad_addr no-undo.

   err = false.

   for first ls_mstr where ls_addr = shipto
      and (ls_type = "customer"
        or ls_type = "ship-to"
        or ls_type = "dock") no-lock:
   end.

   for first ad_mstr where
      ad_addr = shipto no-lock:
   end.

   if not available ls_mstr or
      not available ad_mstr then do:
      /* NOT A VALID CUSTOMER OR SHIP-TO */
      {pxmsg.i &MSGNUM=8129 &ERRORLEVEL=3}
      err = true.
      leave.
   end.

   for first cm_mstr where
      cm_addr = shipto no-lock:
   end.

   do while not available cm_mstr and ad_ref > "":
      addr = ad_ref.
      for first ad_mstr where
         ad_addr = addr no-lock:
      end.
      for first cm_mstr where
         cm_addr = ad_addr no-lock:
      end.
   end.

   if not available cm_mstr then do:
      /* NOT A VALID CUSTOMER OR SHIP-TO */
      {pxmsg.i &MSGNUM=8129 &ERRORLEVEL=3}
      err = true.
      leave.
   end.

   if cm_cr_hold then do:
      {pxmsg.i &MSGNUM=614 &ERRORLEVEL=2}  /* CUSTOMER ON CREDIT HOLD */
   end.
END PROCEDURE. /* validate_shipto */

PROCEDURE determine_prev_cum_qty:
   define input parameter ip_up_recid as recid no-undo.
   define input parameter ip_up_from like rcsd_shipfrom no-undo.
   define input parameter ip_up_to   like rcsd_shipto no-undo.
   define input parameter ip_up_id   like rcsd_rlse_id no-undo.
   define input parameter ip_up_part like rcsd_part no-undo.
   define input parameter ip_up_cust_job like rcsd_cust_job no-undo.
   define input parameter ip_up_cust_seq like rcsd_cust_seq no-undo.
   define input parameter ip_up_cust_po  like rcsd_cust_po no-undo.
   define input parameter ip_up_date  like rcsd_date no-undo.
   define input parameter ip_up_time  like rcsd_time no-undo.

   define output parameter op_prev_cum_qty like rcsd_cum_qty no-undo.

   define buffer bf_rcs_mstr for rcs_mstr.
   define buffer bf_rcsd_det for rcsd_det.

   /* INITIALIZE */
   op_prev_cum_qty = 0.

   /* FIND PREVIOUS CUM QTY FROM THE CURRENT SCHEDULE */

   /* IF SCHEDULE CONTAINS SEQ. # BUT NO JOB #     */
   /* THEN FIND PREV USING SEQ. # AND DATE/TIME.   */
   if ip_up_cust_job = "" then
   for last bf_rcsd_det no-lock
      where rcsd_shipfrom = ip_up_from
        and rcsd_shipto   = ip_up_to
        and rcsd_rlse_id  = ip_up_id
        and rcsd_part     = ip_up_part
        and rcsd_cust_po  = ip_up_cust_po
        and rcsd_cust_seq < ip_up_cust_seq
        and recid(bf_rcsd_det) <> ip_up_recid
        and (rcsd_date < ip_up_date     or
            (rcsd_date = ip_up_date    and
             rcsd_time <= ip_up_time))
      use-index rcsd_index2:
   end.
   else
   for last bf_rcsd_det no-lock
      where rcsd_shipfrom = ip_up_from
        and rcsd_shipto   = ip_up_to
        and rcsd_rlse_id  = ip_up_id
        and rcsd_part     = ip_up_part
        and rcsd_cust_po  = ip_up_cust_po
        and recid(bf_rcsd_det) <> ip_up_recid
        and (rcsd_cust_job < ip_up_cust_job or
            (rcsd_cust_job = ip_up_cust_job and
             rcsd_cust_seq < ip_up_cust_seq))
        and (rcsd_date < ip_up_date    or
            (rcsd_date = ip_up_date    and
             rcsd_time <= ip_up_time))
      use-index rcsd_index2:
   end.

   if available(bf_rcsd_det) then

   /* ARE THERE > SEQUENCES ON THE SAME DATE WITH LOWER TIME? */
   if can-find (first bf_rcsd_det
      where rcsd_shipfrom = ip_up_from
        and rcsd_shipto   = ip_up_to
        and rcsd_rlse_id  = ip_up_id
        and rcsd_part     = ip_up_part
        and rcsd_cust_po  = ip_up_cust_po
        and rcsd_cust_job = ip_up_cust_job
        and rcsd_cust_seq > ip_up_cust_seq
        and rcsd_date     = ip_up_date
        and rcsd_time     < ip_up_time
        and recid(bf_rcsd_det) <> ip_up_recid
      use-index rcsd_index2) then

   /* FIND THE LAST THE SEQUENCE, BY TIME */
   for last bf_rcsd_det no-lock
      where rcsd_shipfrom = ip_up_from
        and rcsd_shipto   = ip_up_to
        and rcsd_rlse_id  = ip_up_id
        and rcsd_part     = ip_up_part
        and rcsd_cust_po  = ip_up_cust_po
        and rcsd_cust_job = ip_up_cust_job
        and rcsd_cust_seq > ip_up_cust_seq
        and rcsd_date     = ip_up_date
        and rcsd_time     < ip_up_time
        and recid(bf_rcsd_det) <> ip_up_recid
      use-index rcsd_index2:
   end.

   if available(bf_rcsd_det) then
      op_prev_cum_qty = rcsd_cum_qty.
   else do:

      /*FIND THE CURRENT RELEASE SCHEDULE */
      for first bf_rcs_mstr
         where rcs_shipfrom = ip_up_from
           and rcs_shipto   = ip_up_to
           and rcs_rlse_id  = ip_up_id
      no-lock:
      end.

      if available (bf_rcs_mstr) then do:

         /* SEARCH PREVIOUSLY ACTIVE SCHEDULES */
         for each bf_rcs_mstr where
               rcs_shipfrom    = ip_up_from and
               rcs_shipto      = ip_up_to   and
               rcs_rlse_id     <> ip_up_id  and
               rcs_active_date <> ?
               use-index rcs_index2
               by rcs_active_date descending
               by rcs_rlse_id descending:

            /* FIND LAST CUM QTY FROM THE PRIOR SCHEDULE */
            if ip_up_cust_job = "" then
               for last bf_rcsd_det no-lock
                  where rcsd_shipfrom = ip_up_from
                    and rcsd_shipto   = ip_up_to
                    and rcsd_rlse_id  = rcs_rlse_id
                    and rcsd_part     = ip_up_part
                    and rcsd_cust_po  = ip_up_cust_po
                    and rcsd_cust_seq < ip_up_cust_seq
                    and (rcsd_date < ip_up_date      or
                        (rcsd_date = ip_up_date    and
                         rcsd_time <= ip_up_time))
                  use-index rcsd_index2:
               end.
            else
               for last bf_rcsd_det no-lock
                  where rcsd_shipfrom = ip_up_from
                    and rcsd_shipto   = ip_up_to
                    and rcsd_rlse_id  = rcs_rlse_id
                    and rcsd_part     = ip_up_part
                    and rcsd_cust_po  = ip_up_cust_po
                    and (rcsd_cust_job < ip_up_cust_job or
                        (rcsd_cust_job = ip_up_cust_job and
                         rcsd_cust_seq < ip_up_cust_seq))
                    and (rcsd_date < ip_up_date    or
                        (rcsd_date = ip_up_date    and
                         rcsd_time <= ip_up_time))
                  use-index rcsd_index2:
               end.

            if available(bf_rcsd_det) then do:
               op_prev_cum_qty = rcsd_cum_qty.
               leave.
            end.

         end.  /* for each bf_rcs_mstr where */

      end.  /* if available (bf_rcs_mstr) */

   end.  /* if not available(bf_rcsd_det) */

END PROCEDURE. /* determine_prev_cum_qty */

PROCEDURE check_if_seq_skipped:
   /* IF A ALPHANUMERIC SEQUENCE IS FOUND, THEN TOLERANCE CHECKING
   * IS DISABLED AND ISSUE A WARNING,
   * AN "ERROR" CAN ONLY OCCUR WHEN THE MAX TOLERANCE IS EXCEEDED
   * BETWEEN NUMERIC SEQUENCES
   */
   define input parameter ip_int_cust_seq as integer no-undo.
   define input parameter ip_rcs_shipto like rcs_shipto no-undo.
   define input parameter ip_rcs_shipfrom like rcs_shipfrom no-undo.
   define input parameter ip_rlse_id like rcs_rlse_id no-undo.
   define input parameter ip_max_tol like rcs_max_tol no-undo.
   define output parameter op_err_stat like mfc_logical no-undo.

   define variable l_chk_int_cust_seq as integer no-undo.

   define buffer b2_rcsd_det for rcsd_det.

   op_err_stat = false.

   for last b2_rcsd_det
      where rcsd_shipto = ip_rcs_shipto
        and rcsd_shipfrom = ip_rcs_shipfrom
        and rcsd_rlse_id = ip_rlse_id
        and rcsd_cust_seq < string(ip_int_cust_seq)
        and not rcsd_deleted:

   l_chk_int_cust_seq = integer(rcsd_cust_seq) no-error.

   if ERROR-STATUS:ERROR then do:

      /*SEQ ALPHANUMERIC, UNABLE TO CHECK SEQ TOL*/
      run display_std_msg (input 3399, input 2).
      leave.
      end.

   end. /* for last b2_rcsd_det */

   if not available b2_rcsd_det then
   for first b2_rcsd_det
      where rcsd_shipto = ip_rcs_shipto
        and rcsd_shipfrom = ip_rcs_shipfrom
        and rcsd_rlse_id = ip_rlse_id
        and rcsd_cust_seq > string(ip_int_cust_seq):

   l_chk_int_cust_seq = integer(rcsd_cust_seq) no-error.

   if ERROR-STATUS:ERROR then do:
      /*SEQ ALPHANUMERIC, UNABLE TO CHECK SEQ TOL*/
      run display_std_msg (input 3399, input 2).
      leave.
      end.
   end.

   if not available b2_rcsd_det then leave.

   if (ip_int_cust_seq - l_chk_int_cust_seq > ip_max_tol + 1) or
      (l_chk_int_cust_seq - ip_int_cust_seq > ip_max_tol + 1)
   then do:

      /*SEQ TOLERANCE EXCEEDED, PREVIOUS SEQUENCE # */
      {pxmsg.i &MSGNUM=3400 &ERRORLEVEL=2 &MSGARG1=rcsd_cust_seq}
      leave.
   end.
END PROCEDURE. /* check_if_seq_skipped */
